package com.scy.config;

import com.scy.handler.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 本类用来演示
 *
 * @author wwh
 * @date 2024/7/5 13:52 $
 */
//@Configuration
public class WebMVCConfig implements WebMvcConfigurer {
    @Resource
    LoginInterceptor loginInterceptor;

//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        WebMvcConfigurer.super.addCorsMappings(registry);
//    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //拦截test接口，后续实际遇到需要拦截的接口时，再配置为真正的拦截接口
        //.addPathPatterns("/**") 表示拦截所有接口
        //.excludePathPatterns("/login").excludePathPatterns("/register") 表示不拦截登录和注册接口
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/login")
                .excludePathPatterns("/register")
                .excludePathPatterns("/doc.html*/**","/**/*.css", "/**/*.js", "/**/*.png", "/**/*.jpg","/**/*.jpeg", "/**/*.gif", "/**/fonts/*", "/**/*.svg");

    }
}
